package com.dwms.controller;

import com.dwms.entity.DictInfoVO;
import com.dwms.entity.PageResponse;
import com.dwms.entity.QueryRequest;
import com.dwms.entity.Result;
import com.dwms.entity.system.dict.item.request.DictItemQueryRequest;
import com.dwms.entity.system.dict.item.request.DictItemRequest;
import com.dwms.entity.system.dict.item.response.DictItemResponse;
import com.dwms.entity.system.dict.request.DictQueryRequest;
import com.dwms.entity.system.dict.request.DictRequest;
import com.dwms.entity.system.dict.response.DictResponse;
import com.dwms.feign.system.DictFeignClient;
import com.dwms.utils.WebUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @ClassName: DictMapper
 * @Description: Dict
 * @Create 2022/03/05 20:46
 * @Author WH
 * @Since 2.0.0
**/
@Tag(name = "数据字典管理")
@RestController(value = "DictController")
@RequestMapping(value = "/system/dict")
@RequiredArgsConstructor
public class DictController {

    private final HttpServletRequest request;
    private final DictFeignClient dictFeignClient;

    @Operation(summary = "新增数据字典")
    @PostMapping("/save")
    public Result save(@RequestBody DictRequest dictRequest) {
        WebUtil.getAdminRequest(request,dictRequest);
        return dictFeignClient.save(dictRequest);
    }

    @Operation(summary = "修改数据字典")
    @PostMapping("/update")
    public Result update(@RequestBody DictRequest dictRequest) {
        WebUtil.getAdminRequest(request,dictRequest);
        return dictFeignClient.update(dictRequest);
    }

    @Operation(summary = "分页查询数据字典")
    @PostMapping("/findPage")
    public Result<PageResponse<DictResponse>> findPage(@RequestBody DictQueryRequest query) {
        WebUtil.getAdminRequest(request,query);
        return dictFeignClient.findPage(query);
    }

    @Operation(summary = "根据ID查询")
    @PostMapping("/findById")
    public Result findById(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return dictFeignClient.findById(query);
    }

    @Operation(summary = "删除数据字典")
    @PostMapping("/delete")
    public Result delete(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return dictFeignClient.delete(query);
    }

    @Operation(summary = "新增字典明细")
    @PostMapping("/saveItem")
    public Result saveItem(@RequestBody DictItemRequest dictItemRequest) {
        WebUtil.getAdminRequest(request, dictItemRequest);
        return dictFeignClient.saveItem(dictItemRequest);
    }

    @Operation(summary = "修改字典明细")
    @PostMapping("/updateItem")
    public Result updateItem(@RequestBody DictItemRequest dictItemRequest) {
        WebUtil.getAdminRequest(request,dictItemRequest);
        return dictFeignClient.updateItem(dictItemRequest);
    }

    @Operation(summary = "分页查询字典明细")
    @PostMapping("/findItemPage")
    public Result<PageResponse<DictItemResponse>> findItemPage(@RequestBody DictItemQueryRequest query) {
        WebUtil.getAdminRequest(request,query);
        return dictFeignClient.findItemPage(query);
    }

    @Operation(summary = "根据ID查询明细")
    @PostMapping("/findItemById")
    public Result findItemById(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return dictFeignClient.findItemById(query);
    }

    @Operation(summary = "删除字典明细")
    @PostMapping("/deleteItem")
    public Result deleteItem(@RequestBody QueryRequest query){
        WebUtil.getAdminRequest(request,query);
        return dictFeignClient.deleteItem(query);
    }

    @Operation(summary = "关键字查询")
    @PostMapping("/findByKeywords")
    public Result<List<DictInfoVO>> findByKeywords(@RequestBody DictItemQueryRequest query) {
        WebUtil.getAdminRequest(request,query);
        return dictFeignClient.findByKeywords(query);
    }
}
